#include "longestCommonSubsequence.h"
int longestCommonSubsequence(string text1, string text2) {
<<<<<<< HEAD
=======
  int size1 = text1.size();
  int size2 = text2.size();
  int dp[size2 + 1][size1 + 1];
  for (int i = 0; i < size2 + 1; i++) {
    for (int j = 0; j < size1 + 1; j++) {
      if (i == 0 || j == 0)
        dp[i][j] = 0;
      else if (text1[j - 1] == text2[i - 1])
        dp[i][j] = dp[i - 1][j - 1] + 1;
      else {
        dp[i][j] = std::max(dp[i - 1][j], dp[i][j - 1]);
      }
    }
  }
  return dp[size2][size1];
}

int longestCommonSubsequenceMem(string text1, string text2) {
>>>>>>> dev
  int size_1 = text1.length() + 1;
  int size_2 = text2.length() + 1;
  vector<vector<int>> DP(size_1, vector<int>(size_2, 0));
  for (int i = 0; i < size_1; i++) {
    for (int j = 0; j < size_2; j++) {
      if (i == 0 || j == 0) {
        DP[i][j] = 0;
      } else if (text1.at(i - 1) == text2.at(j - 1)) {
        DP[i][j] = DP[i - 1][j - 1] + 1;
      } else
        DP[i][j] = std::max(DP[i - 1][j], DP[i][j - 1]);
    }
  }
  return DP[size_1 - 1][size_2 - 1];
}
<<<<<<< HEAD
int longestCommonSubsequence1(string text1, string text2, int i, int j,
                              vector<vector<int>> &dp) {
=======

int longestCommonSubsequence1(string text1, string text2) {
  int a_length = text1.size();
  int b_length = text2.size();
  int dp[a_length + 1][b_length + 1];
  for (int i = 0; i < a_length + 1; i++) {
    for (int j = 0; j < b_length + 1; j++) {
      if (i == 0 || j == 0)
        dp[i][j] = 0;
      else if (text1.at(i - 1) == text2.at(j - 1))
        dp[i][j] = dp[i - 1][j - 1] + 1;
      else {
        dp[i][j] = std::max(dp[i - 1][j], dp[i][j - 1]);
      }
    }
  }

  return dp[a_length][b_length];
}
int longestCommonSubsequenceRec(string text1, string text2, int i, int j,
                                vector<vector<int>> &dp) {
>>>>>>> dev
  if (i == 0 || j == 0) {
    return 0;
  }
  if (text1[i - 1] == text2[j - 1]) {
    if (dp[i - 1][j - 1] == 0) {
      dp[i - 1][j - 1] =
<<<<<<< HEAD
          longestCommonSubsequence1(text1, text2, i - 1, j - 1, dp);
      
=======
          longestCommonSubsequenceRec(text1, text2, i - 1, j - 1, dp);
>>>>>>> dev
    }
    dp[i][j] = dp[i - 1][j - 1] + 1;
  } else {
    if (dp[i - 1][j] == 0)
<<<<<<< HEAD
      dp[i - 1][j] = longestCommonSubsequence1(text1, text2, i - 1, j, dp);
    if (dp[i][j - 1] == 0)
      dp[i][j - 1] = longestCommonSubsequence1(text1, text2, i, j - 1, dp);
    dp[i][j] = dp[i - 1][j] > dp[i ][j-1] ? dp[i - 1][j] : dp[i][j-1];
  }
  return dp[i][j];
}
int longestCommonSubsequence1(string text1, string text2) {
  int size_1 = text1.length();
  int size_2 = text2.length();
  vector<vector<int>> DP(size_1 + 1, vector<int>(size_2 + 1, 0));
  return longestCommonSubsequence1(text1, text2, size_1, size_2, DP);
}
=======
      dp[i - 1][j] = longestCommonSubsequenceRec(text1, text2, i - 1, j, dp);
    if (dp[i][j - 1] == 0)
      dp[i][j - 1] = longestCommonSubsequenceRec(text1, text2, i, j - 1, dp);
    dp[i][j] = dp[i - 1][j] > dp[i][j - 1] ? dp[i - 1][j] : dp[i][j - 1];
  }
  return dp[i][j];
}
int longestCommonSubsequenceRec(string text1, string text2) {
  int size_1 = text1.length();
  int size_2 = text2.length();
  vector<vector<int>> DP(size_1 + 1, vector<int>(size_2 + 1, 0));
  return longestCommonSubsequenceRec(text1, text2, size_1, size_2, DP);
}
>>>>>>> dev
